<?php
/* 	These code was generated using phpCIGen v 0.1.b (24/06/2009)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com,
	#CV. Trust Solution, jl. Saronojiwo 19 Surabaya, http://www.ts.co.id

	+ Module  		: t_bill View
	+ Description	: For record view
	+ Filename 		: v_t_bill.php
 	+ creator  		: 
 	+ Created on 06/Mar/2012 12:35:49

*/
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<style type="text/css">
        p { width:650px; }
		.search-item {
			font:normal 11px tahoma, arial, helvetica, sans-serif;
			padding:3px 10px 3px 10px;
			border:1px solid #fff;
			border-bottom:1px solid #eeeeee;
			white-space:normal;
			color:#555;
		}
		.search-item h3 {
			display:block;
			font:inherit;
			font-weight:bold;
			color:#222;
		}

		.search-item h3 span {
			float: right;
			font-weight:normal;
			margin:0 0 5px 5px;
			width:100px;
			display:block;
			clear:none;
		}
    </style>
<script>
/* declare function */
var t_bill_DataStore;
var t_bill_ColumnModel;
var t_bill_ListEditorGrid;
var t_bill_saveForm;
var t_bill_searchForm;
var t_bill_searchWindow;
var t_bill_SelectedRow;
var t_bill_ContextMenu;
/* decalare KONSTANSTA */
var FAILED_SAVE="Data gagal disimpan";
var FAILED_CONNECTION="Koneksi database server gagal, hubungi Administrator";
var FAILED_VALID_FORM="Data input belum sempurna";
var FAILED_DELETE_SELECTED="Tidak ada data yang terpilih untuk dihapus";
var FAILED_UPDATE_SELECTED="Tidak ada data yang terpilih untuk diupdate";
var FAILED_DELETE="Data gagal dihapus";
var FAILED_EXCEL="Data gagal diexport ke Excel";
var FAILED_PRINT="Data gagal dicetak";
var FAILED_PERMISSION="Anda tidak mempunyai akses untuk aksi ini";
var CONFIRM_DELETE="Apakah Anda yakin menghapus rekod ini?";
var CONFIRM_MULTI_DELETE="Apakah Anda yakin menghapus rekod-rekod ini?";
var SUCCESS_SAVE="Data sukses disimpan";
var TITLE_LIST="Daftar Data";
var TITLE_FORM="Form Input/Update";
var TITLE_FORM_SEARCH="Pencarian Lanjut";
var BTN_SAVE="Simpan";
var BTN_SEARCH="Cari";
var BTN_CANCEL="Batal";
var BTN_ADD_TITLE="Tambah";
var BTN_EDIT_TITLE="Ubah";
var BTN_DELETE_TITLE="Hapus";
var BTN_SEARCH_TITLE="Pencarian";
var BTN_PRINT_TITLE="Cetak";
var BTN_EXCEL_TITLE="Export Excel";
var BTN_REFRESH_TITLE="Refresh Data";
var BTN_ADD_TOOLTIP="Tambah Data Baru";
var BTN_EDIT_TOOLTIP="Ubah Data";
var BTN_DELETE_TOOLTIP="Hapus Data";
var BTN_SEARCH_TOOLTIP="Pencarian Lanjut Data";
var BTN_SIMPLE_SEARCH_TOOLTIP="Pencarian Sederhana";
var BTN_PRINT_TOOLTIP="Cetak Data (hmtl)";
var BTN_EXCEL_TOOLTIP="Export ke bentuk Excel";
var BTN_REFERSH_TOOLTIP="Refresh Data";
var INFO_REQUIRED="Wajib diisi";
var PERMISSION="RCUD";
//declare konstant
var post2db = 'CREATE';
var msg = 'created';
var pageS=15;

/* declare variable here for Field*/
var bill_idField;
var t_order_idField;
var bill_dateField;
var bill_noField;
var bill_valueField;
var bill_noteField;
var bill_statField;
/* For search form */
var bill_idSearchField;
var t_order_idSearchField;
var bill_dateSearchField;
var bill_noSearchField;
var bill_valueSearchField;
var bill_noteSearchField;
var bill_statSearchField;

/* on ready fuction */
Ext.onReady(function(){
  	Ext.QuickTips.init();	/* Initiate quick tips icon */
        
  	/* Function for Saving inLine Editing */
	function t_bill_inline_update(oGrid_event){

	var patt=new RegExp("U");
	if(patt.test(PERMISSION)==false){

		Ext.MessageBox.show({
		   title: 'Warning',
		   msg: FAILED_PERMISSION,
		   buttons: Ext.MessageBox.OK,
		   animEl: 'security',
		   icon: Ext.MessageBox.WARNING
		});

	}else{

		var bill_id_update=null;
		var t_order_id_update=null;
		var bill_date_update_date="";
		var bill_no_update=null;
		var bill_value_update=null;
		var bill_note_update=null;
		var bill_stat_update=null;

		if(oGrid_event.record.data.bill_id!== null){bill_id_update = oGrid_event.record.data.bill_id;}
		if(oGrid_event.record.data.t_order_id!== null){t_order_id_update = oGrid_event.record.data.t_order_id;}
	 	if(oGrid_event.record.data.bill_date!== ""){bill_date_update_date =oGrid_event.record.data.bill_date.format('Y-m-d');}
		if(oGrid_event.record.data.bill_no!== null){bill_no_update = oGrid_event.record.data.bill_no;}
		if(oGrid_event.record.data.bill_value!== null){bill_value_update = oGrid_event.record.data.bill_value;}
		if(oGrid_event.record.data.bill_note!== null){bill_note_update = oGrid_event.record.data.bill_note;}
		if(oGrid_event.record.data.bill_stat!== null){bill_stat_update = oGrid_event.record.data.bill_stat;}

		Ext.Ajax.request({
			waitMsg: 'Please wait...',
			url: 'index.php?c=c_t_bill&m=get_action',
			params: {
				bill_id	:bill_id_update,
				t_order_id	:t_order_id_update,
				bill_date	: bill_date_update_date,
				bill_no	:bill_no_update,
				bill_value	:bill_value_update,
				bill_note	:bill_note_update,
				bill_stat	:bill_stat_update,
				task: "UPDATE"
			},
			success: function(response){
				var result=eval(response.responseText);
				switch(result){
					case 1:
						t_bill_DataStore.commitChanges();
						t_bill_DataStore.reload();
						break;
					default:
						Ext.MessageBox.show({
						   title: 'Warning',
						   msg: FAILED_SAVE,
						   buttons: Ext.MessageBox.OK,
						   animEl: 'save',
						   icon: Ext.MessageBox.WARNING
						});
						break;
				}
			},
			failure: function(response){
				var result=response.responseText;
				Ext.MessageBox.show({
				   title: 'Error',
				   msg: FAILED_CONNECTION,
				   buttons: Ext.MessageBox.OK,
				   animEl: 'database',
				   icon: Ext.MessageBox.ERROR
				});
			}
		});

		}
	}
  	/* End of Function */

  	/* Function for add and edit data form, open window form */
	function t_bill_save(){

		var patt=new RegExp("U");
		var patt2=new RegExp("C");
		if(patt.test(PERMISSION)==false && patt2.test(PERMISSION)==false){

			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: FAILED_PERMISSION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'security',
			   icon: Ext.MessageBox.WARNING
			});

		}else{

		if(is_t_bill_form_valid()){
			var bill_id_field=null;
			var t_order_id_field=null;
			var bill_date_field_date="";
			var bill_no_field=null;
			var bill_value_field=null;
			var bill_note_field=null;
			var bill_stat_field=null;

			if(bill_idField.getValue()!== null){bill_id_field = bill_idField.getValue();}
			if(t_order_idField.getValue()!== null){t_order_id_field = t_order_idField.getValue();}
			if(bill_dateField.getValue()!== ""){bill_date_field_date = bill_dateField.getValue().format('Y-m-d');}
			if(bill_noField.getValue()!== null){bill_no_field = bill_noField.getValue();}
			if(bill_valueField.getValue()!== null){bill_value_field = bill_valueField.getValue();}
			if(bill_noteField.getValue()!== null){bill_note_field = bill_noteField.getValue();}
			if(bill_statField.getValue()!== null){bill_stat_field = bill_statField.getValue();}

			Ext.Ajax.request({
				waitMsg: 'Please wait...',
				url: 'index.php?c=c_t_bill&m=get_action',
				params: {
					bill_id	: bill_id_field,
					t_order_id	: t_order_id_field,
					bill_date	: bill_date_field_date,
					bill_no	: bill_no_field,
					bill_value	: bill_value_field,
					bill_note	: bill_note_field,
					bill_stat	: bill_stat_field,
					task: post2db
				},
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:
							Ext.MessageBox.alert(post2db+' OK',SUCCESS_SAVE);
							t_bill_DataStore.reload();
							t_bill_reset_form();
							break;
						default:
							Ext.MessageBox.show({
							   title: 'Warning',
							   msg: FAILED_SAVE,
							   buttons: Ext.MessageBox.OK,
							   animEl: 'save',
							   icon: Ext.MessageBox.WARNING
							});
							break;
					}
				},
				failure: function(response){
					var result=response.responseText;
					Ext.MessageBox.show({
						   title: 'Error',
						   msg: FAILED_CONNECTION,
						   buttons: Ext.MessageBox.OK,
						   animEl: 'database',
						   icon: Ext.MessageBox.ERROR
					});
				}
			});

		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_VALID_FORM,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}

		}
	}
 	/* End of Function */

  	/* Function for get PK field */
	function get_pk_id(){
		if(post2db=='UPDATE')
			return t_bill_ListEditorGrid.getSelectionModel().getSelected().get('bill_id');
		else
			return 0;
	}
	/* End of Function  */

	/* Reset form before loading */
	function t_bill_reset_form(){
		post2db="CREATE";
		bill_idField.reset();
		bill_idField.setValue(null);
		t_order_idField.reset();
		t_order_idField.setValue(null);
		bill_dateField.reset();
		bill_dateField.setValue(null);
		bill_noField.reset();
		bill_noField.setValue(null);
		bill_valueField.reset();
		bill_valueField.setValue(null);
		bill_noteField.reset();
		bill_noteField.setValue(null);
		bill_statField.reset();
		bill_statField.setValue(null);

		t_bill_saveForm.kuitansiPrint.disable();
		t_bill_saveForm.notaPrint.disable();
		t_bill_saveForm.surat_jalanPrint.disable();
	}
 	/* End of Function */

	/* setValue to EDIT */
	function t_bill_set_form(){
		bill_idField.setValue(t_bill_ListEditorGrid.getSelectionModel().getSelected().get('bill_id'));
		t_order_idField.setValue(t_bill_ListEditorGrid.getSelectionModel().getSelected().get('t_order_id'));
		bill_dateField.setValue(t_bill_ListEditorGrid.getSelectionModel().getSelected().get('bill_date'));
		bill_noField.setValue(t_bill_ListEditorGrid.getSelectionModel().getSelected().get('bill_no'));
		bill_valueField.setValue(t_bill_ListEditorGrid.getSelectionModel().getSelected().get('bill_value'));
		bill_noteField.setValue(t_bill_ListEditorGrid.getSelectionModel().getSelected().get('bill_note'));
		bill_statField.setValue(t_bill_ListEditorGrid.getSelectionModel().getSelected().get('bill_stat'));
	}
	/* End setValue to EDIT*/

	/* Function for Check if the form is valid */
	function is_t_bill_form_valid(){
		return (true  																												);
	}
  	/* End of Function */

  	/* Function for Displaying  create Window Form */
	function display_form_window(){
			post2db='CREATE';
			msg='created';
			t_bill_reset_form();
	}
  	/* End of Function */

  	/* Function for Delete Confirm */
	function t_bill_confirm_delete(){
		// only one t_bill is selected here
		if(t_bill_ListEditorGrid.selModel.getCount() == 1){
			Ext.MessageBox.confirm('Confirmation',CONFIRM_DELETE, t_bill_delete);
		} else if(t_bill_ListEditorGrid.selModel.getCount() > 1){
			Ext.MessageBox.confirm('Confirmation',CONFIRM_MULTI_DELETE, t_bill_delete);
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_DELETE_SELECTED,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
  	/* End of Function */

	/* Function for Update Confirm */
	function t_bill_confirm_update(){
		/* only one record is selected here */
		if(t_bill_ListEditorGrid.selModel.getCount() == 1) {
			post2db='UPDATE';
			msg='updated';
			t_bill_set_form();
			t_bill_saveForm.kuitansiPrint.enable();
			t_bill_saveForm.notaPrint.enable();
			t_bill_saveForm.surat_jalanPrint.enable();
		} else {
			Ext.MessageBox.show({
				title: 'Warning',
				msg: FAILED_UPDATE_SELECTED,
				buttons: Ext.MessageBox.OK,
				animEl: 'save',
				icon: Ext.MessageBox.WARNING
			});
		}
	}
  	/* End of Function */

  	/* Function for Delete Record */
	function t_bill_delete(btn){
		if(btn=='yes'){

		var patt=new RegExp("D");
		if(patt.test(PERMISSION)==false){

			Ext.MessageBox.show({
			   title: 'Warning',
			   msg: FAILED_PERMISSION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'security',
			   icon: Ext.MessageBox.WARNING
			});

		}else{

			var selections = t_bill_ListEditorGrid.selModel.getSelections();
			var prez = [];
			for(i = 0; i< t_bill_ListEditorGrid.selModel.getCount(); i++){
				prez.push(selections[i].json.bill_id);
			}
			var encoded_array = Ext.encode(prez);
			Ext.Ajax.request({
				waitMsg: 'Please Wait',
				url: 'index.php?c=c_t_bill&m=get_action',
				params: { task: "DELETE", ids:  encoded_array },
				success: function(response){
					var result=eval(response.responseText);
					switch(result){
						case 1:
							t_bill_DataStore.reload();
							break;
						default:
							Ext.MessageBox.show({
								title: 'Warning',
								msg: FAILED_DELETE,
								buttons: Ext.MessageBox.OK,
								animEl: 'save',
								icon: Ext.MessageBox.WARNING
							});
							break;
					}
				},
				failure: function(response){
					var result=response.responseText;
					Ext.MessageBox.show({
					   title: 'Error',
					   msg: FAILED_CONNECTION,
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
					});
				}
			});

			}

		}
	}
  	/* End of Function */

	/* Function for Retrieve DataStore */
	t_bill_DataStore = new Ext.data.Store({
		id: 't_bill_DataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_t_bill&m=get_action',
			method: 'POST'
		}),
		baseParams:{task: "LIST", start:0, limit: pageS},
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'bill_id'
		},[
			{name: 'bill_id', type: 'int', mapping: 'bill_id'},			
                        {name: 't_order_id', type: 'string', mapping: 'order_code'},			
                        {name: 'bill_date', type: 'date', dateFormat: 'Y-m-d H:i:s', mapping: 'bill_date'},
			{name: 'bill_no', type: 'string', mapping: 'bill_no'},			
                        {name: 'bill_value', type: 'float', mapping: 'bill_value'},			
                        {name: 'bill_note', type: 'string', mapping: 'bill_note'},			
                        {name: 'bill_stat', type: 'string', mapping: 'bill_stat'}		
                   ]),
		sortInfo:{field: 'bill_id', direction: "DESC"}
	});
        
        t_order_DataStore = new Ext.data.Store({
		id: 't_order_DataStore',
		proxy: new Ext.data.HttpProxy({
			url: 'index.php?c=c_public_function&m=get_t_order_forbill',
			method: 'POST'
		}),
		baseParams:{start:0, limit: pageS},
		reader: new Ext.data.JsonReader({
			root: 'results',
			totalProperty: 'total',
			id: 'order_id'
		},[
			{name: 'order_id', type: 'int', mapping: 'order_id'},
			{name: 'order_code', type: 'string', mapping: 'order_code'},
                        {name: 'customer_name', type: 'string', mapping: 'customer_name'}
		]),
		sortInfo:{field: 'order_code', direction: "ASC"}
	});
        
        var t_order_tpl = new Ext.XTemplate(
        '<tpl for="."><div class="search-item">',
            '<span><b>{order_code}</b><br /></span>',
            '[{customer_name}]<br>',
        '</div></tpl>'
        );
        
        
	/* End of Function */

  	/* Function for Identify of Window Column Model */
	t_bill_ColumnModel = new Ext.grid.ColumnModel(
		[
		{
			header: 'Bill Id',
			dataIndex: 'bill_id',
			width: 150,
			sortable: true,
                        hidden: true,
			editor: new Ext.form.NumberField({
				allowDecimals: false,
					allowNegative: false,
				blankText: '0',
				maxLength: 11,
				maskRe: /([0-9]+)$/
			})
		},
		{
			header: 'No Order',
			dataIndex: 't_order_id',
			width: 150,
			sortable: true,
			editor: new Ext.form.NumberField({
				allowDecimals: false,
					allowNegative: false,
				blankText: '0',
				maxLength: 11,
				maskRe: /([0-9]+)$/
			})
		},
		{
			header: 'Tgl Tagihan',
			dataIndex: 'bill_date',
			width: 150,
			sortable: true,
			renderer: Ext.util.Format.dateRenderer('Y-m-d')
			/*editor: new Ext.form.DateField({
					format: 'Y-m-d'
			})*/
		},
		{
			header: 'No Tagihan',
			dataIndex: 'bill_no',
			width: 150,
			sortable: true
			/*editor: new Ext.form.TextArea({
					height: 5
			})*/
		},
		{
			header: 'Nilai Tagihan',
			dataIndex: 'bill_value',
			width: 150,
			sortable: true,
                        align: 'right',
                        renderer: function(v, params, record){
				return formatCurrency(v);}
			/*editor: new Ext.form.NumberField({
				allowDecimals: true,
					allowNegative: false,
				blankText: '0',
				maxLength: 22,
				maskRe: /([0-9]+)$/
			})*/
		},
		{
			header: 'Catatan',
			dataIndex: 'bill_note',
			width: 150,
			sortable: true
			/*editor: new Ext.form.TextArea({
					height: 5
			})*/
		},
		{
			header: 'Status',
			dataIndex: 'bill_stat',
			width: 150,
			sortable: true
			/*editor: new Ext.form.TextArea({
					height: 5
			})*/
		}	]);

	t_bill_ColumnModel.defaultSortable= true;
	/* End of Function */

    /* Button Control */
    t_bill_gbtn_add=new Ext.Button({
	    text: BTN_ADD_TITLE,
		tooltip: BTN_ADD_TOOLTIP,
		iconCls:'icon-adds',
		handler: display_form_window
    });

    t_bill_gbtn_update=new Ext.Button({
	    text: BTN_EDIT_TITLE,
		tooltip: BTN_EDIT_TOOLTIP,
		iconCls:'icon-update',
		handler: t_bill_confirm_update
	});

    t_bill_gbtn_delete=new Ext.Button({
	    text: BTN_DELETE_TITLE,
		tooltip: BTN_DELETE_TOOLTIP,
		iconCls:'icon-delete',
		handler: t_bill_confirm_delete
	});

    /*Context Menu Button */

	t_bill_cbtn_update=new Ext.menu.Item({
		text: BTN_EDIT_TITLE,
		tooltip: BTN_EDIT_TOOLTIP,
		iconCls:'icon-update',
		handler: t_bill_editContextMenu
	});

	t_bill_cbtn_delete=new Ext.menu.Item({
		text: BTN_DELETE_TITLE,
		tooltip: BTN_DELETE_TOOLTIP,
		iconCls:'icon-delete',
		handler: t_bill_confirm_delete
	});

	/* Declare DataStore and  show datagrid list */
	t_bill_ListEditorGrid =  new Ext.grid.EditorGridPanel({
		id: 't_bill_ListEditorGrid',
		el: 'fp_t_bill',
		title: TITLE_LIST,
		autoHeight: true,
		collapsible: true,
		store: t_bill_DataStore, // DataStore
		cm: t_bill_ColumnModel, // Nama-nama Columns
		enableColLock:false,
		frame: true,
		clicksToEdit:2, // 2xClick untuk bisa meng-Edit inLine Data
		selModel: new Ext.grid.RowSelectionModel({singleSelect:false}),
		viewConfig: { forceFit:true },
	  	width: 700,
		bbar: new Ext.PagingToolbar({
			pageSize: pageS,
			store: t_bill_DataStore,
			displayInfo: true
		}),
		/* Add Control on ToolBar */
		tbar: [
		t_bill_gbtn_add, '-',
		t_bill_gbtn_update, '-',
		t_bill_gbtn_delete, '-',
		{
			text: BTN_SEARCH_TITLE,
			tooltip: BTN_SEARCH_TOOLTIP,
			iconCls:'icon-search',
			handler: display_form_search_window
		}, '-',
		new Ext.app.SearchField({
			store: t_bill_DataStore,
			listeners:{
				specialkey: function(f,e){
					if(e.getKey() == e.ENTER){
						t_bill_DataStore.baseParams={task:'LIST', start:0, limit:pageS};
		            }
				},
				render: function(c){
				Ext.get(this.id).set({qtitle: BTN_SIMPLE_SEARCH_TOOLTIP});
				}
			},
			width: 120
		}),'-',{
			text: BTN_REFRESH_TITLE,
			tooltip: BTN_REFERSH_TOOLTIP,
			handler: t_bill_reset_search,
			iconCls:'icon-refresh'
		},'-',{
			text: BTN_EXCEL_TITLE,
			tooltip: BTN_EXCEL_TOOLTIP,
			iconCls:'icon-xls',
			handler: t_bill_export_excel
		}, '-',{
			text: BTN_PRINT_TITLE,
			tooltip: BTN_PRINT_TOOLTIP,
			iconCls:'icon-print',
			handler: t_bill_print
		}
		]
	});
	t_bill_ListEditorGrid.render();
	/* End of DataStore */

	/* Create Context Menu */
	t_bill_ContextMenu = new Ext.menu.Menu({
		id: 't_bill_ContextMenu',
		items: [
		t_bill_cbtn_update,
		t_bill_cbtn_delete,
		'-',
		{
			text: BTN_PRINT_TITLE,
			tooltip: BTN_PRINT_TOOLTIP,
			iconCls:'icon-print',
			handler: t_bill_print
		},
		{
			text: BTN_EXCEL_TITLE,
			tooltip: BTN_EXCEL_TOOLTIP,
			iconCls:'icon-xls',
			handler: t_bill_export_excel
		}
		]
	});
	/* End of Declaration */

	/* Event while selected row via context menu */
	function ont_bill_ContextMenu(grid, rowIndex, e) {
		e.stopEvent();
		var coords = e.getXY();
		t_bill_ContextMenu.rowRecord = grid.store.getAt(rowIndex);
		grid.selModel.selectRow(rowIndex);
		t_bill_SelectedRow=rowIndex;
		t_bill_ContextMenu.showAt([coords[0], coords[1]]);
  	}
  	/* End of Function */

	/* function for editing row via context menu */
	function t_bill_editContextMenu(){
		//t_bill_ListEditorGrid.startEditing(t_bill_SelectedRow,1);
		t_bill_confirm_update();
  	}
	/* End of Function */

	t_bill_ListEditorGrid.addListener('rowcontextmenu', ont_bill_ContextMenu);
	t_bill_DataStore.load({params: {start: 0, limit: pageS}});	// load DataStore
	//t_bill_ListEditorGrid.on('afteredit', t_bill_inline_update); // inLine Editing Record

	bill_idField= new Ext.form.NumberField({
		id: 'bill_idField',
		fieldLabel: 'Bill Id ',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
                hidden: true,
		maskRe: /([0-9]+)$/
	});
        t_order_idField= new Ext.form.ComboBox({
		id: 't_order_idField',
		fieldLabel: 'No Order <font color=red>*</font>',
                emptyText: 'Pilih No Order',
		store: t_order_DataStore,
		mode: 'remote',
		displayField:'order_code',
                valueField: 'order_id',
		allowBlank: false,
		editable: true,
		anchor: '95%',
		pageSize: 15,
                tpl: t_order_tpl,
                itemSelector: 'div.search-item',
		triggerAction: 'all'
	});
        //test ambil nilai total tagihan
        t_order_idField.on('select',function(){
		Ext.MessageBox.show({
			msg: 'Sedang memuat data, silakan tunggu...',
			progressText: 'Loading...',
			width:350,
			wait:true,
			icon:'icon-sync'
		});
		
		var order_id=t_order_idField.getValue();
                get_totaltag_byorder(order_id);
		//m_warehouse_DataStore.baseParams=({start:0, limit: pageS, order: select_order });
		//m_warehouse_DataStore.load({start:0, limit: pageS, order: select_order});
		//m_warehouse_idField.update();
		bill_valueField.setValue("");
		Ext.MessageBox.hide();
		//console.log(noso);
	});
	bill_dateField= new Ext.form.DateField({
		id: 'bill_dateField',
		fieldLabel: 'Tgl Tagihan ',
		format : 'Y-m-d',
		anchor: '95%'
	});
	bill_noField= new Ext.form.TextField({
		id: 'bill_noField',
		fieldLabel: 'No Tagihan ',
		maxLength: 30,
		anchor: '95%'
	});
	bill_valueField= new Ext.form.NumberField({
		id: 'bill_valueField',
		fieldLabel: 'Nilai Tagihan ',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: true,
		anchor: '95%',
                itemCls: 'rmoney',
		maskRe: /([0-9]+)$/
	});
	bill_noteField= new Ext.form.TextArea({
		id: 'bill_noteField',
		fieldLabel: 'Catatan ',
		maxLength: 200,
		anchor: '95%'
	});
	bill_statField= new Ext.form.TextField({
		id: 'bill_statField',
		fieldLabel: 'Status ',
		maxLength: 10,
		anchor: '95%'
	});


	t_bill_btn_Save=new Ext.Button({
		text: BTN_SAVE,
		handler: t_bill_save
	})
	/* Function for retrieve create Window Panel*/
	t_bill_saveForm = new Ext.FormPanel({
		labelAlign: 'left',
		title: TITLE_FORM+' T Bill',
		bodyStyle:'padding:5px',
		autoHeight:true,
		layout:'column',
		width: 700,
		collapsible: true,
		frame: true,
		renderTo: 'elwindow_t_bill_save',
		items:[
			{
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items: [t_order_idField,bill_dateField, bill_noField, ] 
			},
                        {
				columnWidth:0.5,
				layout: 'form',
				border:false,
				items: [bill_valueField, bill_noteField,new  Ext.form.Label({html:'Keterangan : <font color=red>*</font>  '+INFO_REQUIRED })] 
			}
			],
		buttons: [
			{
				text: 'Cetak Kuitansi',
				ref: '../kuitansiPrint',
				handler: print_kuitansi
			},
			{
				text: 'Cetak Nota',
				ref: '../notaPrint',
				handler: print_nota
			},
			{
				text: 'Cetak Surat Jalan',
				ref: '../surat_jalanPrint',
				//handler: print_only
			},
		  	{
				xtype:'spacer',
				width: 245
			},t_bill_btn_Save
			,{
				text: BTN_CANCEL,
				handler: function(){
					t_bill_reset_form();
				}
			}
		]
	});
	t_bill_saveForm.kuitansiPrint.disable();
	t_bill_saveForm.notaPrint.disable();
	t_bill_saveForm.surat_jalanPrint.disable();
	/* End  of Function*/
	
	function print_kuitansi(){ 
		Ext.Ajax.request({   
			waitMsg: 'Mohon tunggu...',
			url: 'index.php?c=c_t_bill&m=cetak',
			params: { 
				bill_id : bill_idField.getValue(), 
				jenis	: 'kuitansi'
			},
			success: function(response){
				var result=eval(response.responseText);
				switch(result){
				case 1:
					win = window.open('./bill_kuitansi_paper.html','Cetak Kuitansi Tagihan','height=480,width=1340,resizable=1,scrollbars=1, menubar=0');
					//win.print();
					break;
				default:
					Ext.MessageBox.show({
						title: 'Warning',
						msg: 'Unable to print the grid!',
						buttons: Ext.MessageBox.OK,
						animEl: 'save',
						icon: Ext.MessageBox.WARNING
					});
					break;
				}  
			},
			failure: function(response){
				var result=response.responseText;
				Ext.MessageBox.show({
				   title: 'Error',
				   msg: 'Could not connect to the database. retry later.',
				   buttons: Ext.MessageBox.OK,
				   animEl: 'database',
				   icon: Ext.MessageBox.ERROR
				});		
			} 	                     
		});
	}

	function print_nota(){ 
		Ext.Ajax.request({   
			waitMsg: 'Mohon tunggu...',
			url: 'index.php?c=c_t_bill&m=cetak',
			params: { 
				bill_id : bill_idField.getValue(), 
				jenis	: 'nota'
			},
			success: function(response){
				var result=eval(response.responseText);
				switch(result){
				case 1:
					win = window.open('./bill_nota_paper.html','Cetak Nota Tagihan','height=480,width=1340,resizable=1,scrollbars=1, menubar=0');
					//win.print();
					break;
				default:
					Ext.MessageBox.show({
						title: 'Warning',
						msg: 'Unable to print the grid!',
						buttons: Ext.MessageBox.OK,
						animEl: 'save',
						icon: Ext.MessageBox.WARNING
					});
					break;
				}  
			},
			failure: function(response){
				var result=response.responseText;
				Ext.MessageBox.show({
				   title: 'Error',
				   msg: 'Could not connect to the database. retry later.',
				   buttons: Ext.MessageBox.OK,
				   animEl: 'database',
				   icon: Ext.MessageBox.ERROR
				});		
			} 	                     
		});
	}

	function print_srtjln(){ 
		Ext.Ajax.request({   
			waitMsg: 'Mohon tunggu...',
			url: 'index.php?c=c_t_bill&m=cetak',
			params: { 
				bill_id : bill_idField.getValue(), 
				jenis	: 'srtjln'
			},
			success: function(response){
				var result=eval(response.responseText);
				switch(result){
				case 1:
					win = window.open('./bill_srtjln_paper.html','Cetak Surat Jalan','height=480,width=1340,resizable=1,scrollbars=1, menubar=0');
					//win.print();
					break;
				default:
					Ext.MessageBox.show({
						title: 'Warning',
						msg: 'Unable to print the grid!',
						buttons: Ext.MessageBox.OK,
						animEl: 'save',
						icon: Ext.MessageBox.WARNING
					});
					break;
				}  
			},
			failure: function(response){
				var result=response.responseText;
				Ext.MessageBox.show({
				   title: 'Error',
				   msg: 'Could not connect to the database. retry later.',
				   buttons: Ext.MessageBox.OK,
				   animEl: 'database',
				   icon: Ext.MessageBox.ERROR
				});		
			} 	                     
		});
	}


	/* Function for action list search */
	function t_bill_list_search(){

		var bill_id_search=null;
		var t_order_id_search=null;
		var bill_date_search_date="";
		var bill_no_search=null;
		var bill_value_search=null;
		var bill_note_search=null;
		var bill_stat_search=null;

		if(bill_idSearchField.getValue()!==null){bill_id_search=bill_idSearchField.getValue();}
		if(t_order_idSearchField.getValue()!==null){t_order_id_search=t_order_idSearchField.getValue();}
		if(bill_dateSearchField.getValue()!==""){bill_date_search_date=bill_dateSearchField.getValue().format('Y-m-d');}
		if(bill_noSearchField.getValue()!==null){bill_no_search=bill_noSearchField.getValue();}
		if(bill_valueSearchField.getValue()!==null){bill_value_search=bill_valueSearchField.getValue();}
		if(bill_noteSearchField.getValue()!==null){bill_note_search=bill_noteSearchField.getValue();}
		if(bill_statSearchField.getValue()!==null){bill_stat_search=bill_statSearchField.getValue();}

		t_bill_DataStore.baseParams = {
			task: 'SEARCH',
			bill_id	:	bill_id_search,			t_order_id	:	t_order_id_search,			bill_date	:	bill_date_search_date,			bill_no	:	bill_no_search,			bill_value	:	bill_value_search,			bill_note	:	bill_note_search,			bill_stat	:	bill_stat_search		};

		t_bill_DataStore.reload({params: {start: 0, limit: pageS}});
	}

	/* Function for reset search result */
	function t_bill_reset_search(){
		t_bill_DataStore.baseParams = { task: 'LIST' };
		t_bill_DataStore.reload({params: {start: 0, limit: pageS}});
		t_bill_searchWindow.close();
	};
	/* End of Fuction */
        
        /* Function for get total tagihan */
	function get_totaltag_byorder(get_order_id){
		Ext.Ajax.request({
			waitMsg: 'Please wait...',
			url: 'index.php?c=c_public_function&m=get_totaltag_byorder',
			params: {
				order_id	: get_order_id
			},
			success: function(response){
				var result=eval(response.responseText);
				if(result>=0){
                                        //var result= formatCurrency(result);
                                        //alert(result);
					bill_valueField.setValue(result);
				//	maccfinal_totaloutField.setValue(result);
			    }else{
			    	bill_valueField.setValue(0);
                                //maccfinal_totalout_cfField.setValue(formatCurrency(0));
			    	//maccfinal_totaloutField.setValue(0);
				}
			},
			failure: function(response){
				Ext.MessageBox.show({
					   title: 'Error',
					   msg: FAILED_CONNECTION,
					   buttons: Ext.MessageBox.OK,
					   animEl: 'database',
					   icon: Ext.MessageBox.ERROR
				});
			}
		});
	}        
        /* End of Function */

	/* Field for search */
	/* Identify  bill_id Search Field */
	bill_idSearchField= new Ext.form.NumberField({
		id: 'bill_idSearchField',
		fieldLabel: 'Bill Id',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	});
	/* Identify  t_order_id Search Field */
	t_order_idSearchField= new Ext.form.NumberField({
		id: 't_order_idSearchField',
		fieldLabel: 'T Order Id',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: false,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	});
	/* Identify  bill_date Search Field */
	bill_dateSearchField= new Ext.form.DateField({
		id: 'bill_dateSearchField',
		fieldLabel: 'Bill Date',
		format : 'Y-m-d'
	});
	/* Identify  bill_no Search Field */
	bill_noSearchField= new Ext.form.TextField({
		id: 'bill_noSearchField',
		fieldLabel: 'Bill No',
		maxLength: 30,
		anchor: '95%'
	});
	/* Identify  bill_value Search Field */
	bill_valueSearchField= new Ext.form.NumberField({
		id: 'bill_valueSearchField',
		fieldLabel: 'Bill Value',
		allowNegatife : false,
		blankText: '0',
		allowDecimals: true,
		anchor: '95%',
		maskRe: /([0-9]+)$/
	});
	/* Identify  bill_note Search Field */
	bill_noteSearchField= new Ext.form.TextField({
		id: 'bill_noteSearchField',
		fieldLabel: 'Bill Note',
		maxLength: 200,
		anchor: '95%'
	});
	/* Identify  bill_stat Search Field */
	bill_statSearchField= new Ext.form.TextField({
		id: 'bill_statSearchField',
		fieldLabel: 'Bill Stat',
		maxLength: 1,
		anchor: '95%'
	});

	/* Function for retrieve search Form Panel */
	t_bill_searchForm = new Ext.FormPanel({
		labelAlign: 'left',
		layout:'form',
		bodyStyle:'padding:5px',
		autoHeight:true,
		frame: true,
		width: 500,
		items: [bill_idSearchField,
				t_order_idSearchField,
				bill_dateSearchField,
				bill_noSearchField,
				bill_valueSearchField,
				bill_noteSearchField,
				bill_statSearchField
		 ],
		buttons: [{
				text: BTN_SEARCH,
				handler: t_bill_list_search
			},{
				text: BTN_CANCEL,
				handler: function(){
					t_bill_searchWindow.hide();
				}
			}
		]
	});
    /* End of Function */

	/* Function for retrieve search Window Form, used for andvaced search */
	t_bill_searchWindow = new Ext.Window({
		title: TITLE_FORM_SEARCH+'t_bill',
		closable:true,
		closeAction: 'hide',
		autoWidth: true,
		autoHeight: true,
		plain:true,
		layout: 'fit',
		x: 0,
		y: 0,
		modal: true,
		renderTo: 'elwindow_t_bill_search',
		items: t_bill_searchForm
	});
    /* End of Function */

  	/* Function for Displaying  Search Window Form */
	function display_form_search_window(){
		if(!t_bill_searchWindow.isVisible()){
			t_bill_searchWindow.show();
		} else {
			t_bill_searchWindow.toFront();
		}
	}
  	/* End Function */

	/* Function for print List Grid */
	function t_bill_print(){
		var searchquery = "";
		var bill_id_print=null;
		var t_order_id_print=null;
		var bill_date_print_date="";
		var bill_no_print=null;
		var bill_value_print=null;
		var bill_note_print=null;
		var bill_stat_print=null;

		if(t_bill_DataStore.baseParams.query!==null){searchquery = t_bill_DataStore.baseParams.query;}
		if(t_bill_DataStore.baseParams.bill_id!==null){bill_id_print = t_bill_DataStore.baseParams.bill_id;}
		if(t_bill_DataStore.baseParams.t_order_id!==null){t_order_id_print = t_bill_DataStore.baseParams.t_order_id;}
		if(t_bill_DataStore.baseParams.bill_date!==""){bill_date_print_date = t_bill_DataStore.baseParams.bill_date;}
		if(t_bill_DataStore.baseParams.bill_no!==null){bill_no_print = t_bill_DataStore.baseParams.bill_no;}
		if(t_bill_DataStore.baseParams.bill_value!==null){bill_value_print = t_bill_DataStore.baseParams.bill_value;}
		if(t_bill_DataStore.baseParams.bill_note!==null){bill_note_print = t_bill_DataStore.baseParams.bill_note;}
		if(t_bill_DataStore.baseParams.bill_stat!==null){bill_stat_print = t_bill_DataStore.baseParams.bill_stat;}

		Ext.Ajax.request({
		waitMsg: 'Please Wait...',
		url: 'index.php?c=c_t_bill&m=get_action',
		params: {
			task: "PRINT",
		  	query: searchquery,
			bill_id : bill_id_print,
			t_order_id : t_order_id_print,
		  	bill_date : bill_date_print_date,
			bill_no : bill_no_print,
			bill_value : bill_value_print,
			bill_note : bill_note_print,
			bill_stat : bill_stat_print,
		  	currentlisting: t_bill_DataStore.baseParams.task
		},
		success: function(response){
		  	var result=eval(response.responseText);
		  	switch(result){
		  	case 1:
				window.open('./print/t_bill_printlist.html','t_billlist','height=600,width=800,resizable=1,scrollbars=0, menubar=0');
				break;
		  	default:
				Ext.MessageBox.show({
					title: 'Warning',
					msg: FAILED_PRINT,
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
				break;
		  	}
		},
		failure: function(response){
		  	var result=response.responseText;
			Ext.MessageBox.show({
			   title: 'Error',
			   msg: FAILED_CONNECTION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'database',
			   icon: Ext.MessageBox.ERROR
			});
		}
		});
	}
	/* Enf Function */

	/* Function for print Export to Excel Grid */
	function t_bill_export_excel(){
		var searchquery = "";
		var bill_id_2excel=null;
		var t_order_id_2excel=null;
		var bill_date_2excel_date="";
		var bill_no_2excel=null;
		var bill_value_2excel=null;
		var bill_note_2excel=null;
		var bill_stat_2excel=null;

		if(t_bill_DataStore.baseParams.query!==null){searchquery = t_bill_DataStore.baseParams.query;}
		if(t_bill_DataStore.baseParams.bill_id!==null){bill_id_2excel = t_bill_DataStore.baseParams.bill_id;}
		if(t_bill_DataStore.baseParams.t_order_id!==null){t_order_id_2excel = t_bill_DataStore.baseParams.t_order_id;}
		if(t_bill_DataStore.baseParams.bill_date!==""){bill_date_2excel_date = t_bill_DataStore.baseParams.bill_date;}
		if(t_bill_DataStore.baseParams.bill_no!==null){bill_no_2excel = t_bill_DataStore.baseParams.bill_no;}
		if(t_bill_DataStore.baseParams.bill_value!==null){bill_value_2excel = t_bill_DataStore.baseParams.bill_value;}
		if(t_bill_DataStore.baseParams.bill_note!==null){bill_note_2excel = t_bill_DataStore.baseParams.bill_note;}
		if(t_bill_DataStore.baseParams.bill_stat!==null){bill_stat_2excel = t_bill_DataStore.baseParams.bill_stat;}

		Ext.Ajax.request({
		waitMsg: 'Please Wait...',
		url: 'index.php?c=c_t_bill&m=get_action',
		params: {
			task: "EXCEL",
		  	query: searchquery,
			bill_id : bill_id_2excel,
			t_order_id : t_order_id_2excel,
		  	bill_date : bill_date_2excel_date,
			bill_no : bill_no_2excel,
			bill_value : bill_value_2excel,
			bill_note : bill_note_2excel,
			bill_stat : bill_stat_2excel,
		  	currentlisting: t_bill_DataStore.baseParams.task
		},
		success: function(response){
		  	var result=eval(response.responseText);
		  	switch(result){
		  	case 1:
				win = window.location=('./export2excel.php');
				break;
		  	default:
				Ext.MessageBox.show({
					title: 'Warning',
					msg: FAILED_EXCEL,
					buttons: Ext.MessageBox.OK,
					animEl: 'save',
					icon: Ext.MessageBox.WARNING
				});
				break;
		  	}
		},
		failure: function(response){
		  	var result=response.responseText;
			Ext.MessageBox.show({
			   title: 'Error',
			   msg: FAILED_CONNECTION,
			   buttons: Ext.MessageBox.OK,
			   animEl: 'database',
			   icon: Ext.MessageBox.ERROR
			});
		}
		});
	}
	/*End of Function */

	/* Show Hide control for permission */
	var pattr=new RegExp("R");
	var pattc=new RegExp("C");
	var pattu=new RegExp("U");
	var pattd=new RegExp("D");

	if(pattc.test(PERMISSION)==false){
		t_bill_gbtn_add.setVisible(false);
	}else{
		t_bill_gbtn_add.setVisible(true);
	}

	if(pattu.test(PERMISSION)==false){
		t_bill_gbtn_update.setVisible(false);
		t_bill_cbtn_update.setVisible(false);
	}else{
		t_bill_gbtn_update.setVisible(true);
		t_bill_cbtn_update.setVisible(true);
	}

	if(pattd.test(PERMISSION)==false){
		t_bill_gbtn_delete.setVisible(false);
		t_bill_cbtn_delete.setVisible(false);
	}else{
		t_bill_gbtn_delete.setVisible(true);
		t_bill_cbtn_delete.setVisible(true);
	}

	if(pattc.test(PERMISSION)==false && pattu.test(PERMISSION)==false){
		t_bill_btn_Save.setVisible(false);
	}else{
		t_bill_btn_Save.setVisible(true);
	}
});
	</script>
<body style: 'background: url(assets/images/desktop.jpg)'>
<div>
	<div class="col">
		<div id="elwindow_t_bill_save"></div>
		<div>&nbsp;</div>
		<div id="fp_t_bill"></div>
        <div id="elwindow_t_bill_search"></div>
    </div>
</div>
</body>
</html>